<?php
	header ('Access-Control-Allow-Origin: *');
	header ('Access-Control-Allow-Methods: POST');

	include_once ('function/config.php');
	include_once ('function/function.php');

	function checkUpdate($app_code, $version_code) {
		$config = new Config();

		$returnObject = array();

		if (!$app_code || empty($app_code)) {
			$returnObject = (object) array(
				"error_code" => 2004,
				"error_msg" => "参数错误：app_code不能为空",
			);

			return $returnObject;
		}

		if (!$version_code || empty($version_code)) {
			$returnObject = (object) array(
				"error_code" => 2005,
				"error_msg" => "参数错误：version_code不能为空",
			);

			return $returnObject;
		}

		$appsInfo = getUrlData($config->getVersionsFileUrl());
		$jsonObject = json_decode($appsInfo, true);

		$apps = $jsonObject['apps'];

		foreach($apps as $app)
		{
			if ($app["app_code"] == $app_code) {
				if ($app["version_code"] > $version_code) {
					$returnObject = $app;
				}

				break;
			}
		}

		return $returnObject;
	}
?>